<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
</head>
<style>
    .aui-list .aui-list-item:after {
        width: 100%;
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: auto;
        right: auto;
        bottom: 0;
        left: 0;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-list:before {
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: 0;
        left: 0;
        right: auto;
        bottom: auto;
        width: 100%;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-card-list-header {
        color: #212121;
        font-size: 22px;
        font-weight: 600;
    }

    #pn1::after {
        content: "";
        width: 22px;
        height: 22px;
        float: left;
        margin: 0 220px 0 0;
        background: url(../image/pn1.png) no-repeat;
        background-size: 22px 22px;
    }

    #pn2::after {
        content: "";
        width: 22px;
        height: 22px;
        float: left;
        margin: 0 220px 0 0;
        background: url(../image/pn2.png) no-repeat;
        background-size: 22px 22px;
    }

    #pn3::after {
        content: "";
        width: 22px;
        height: 22px;
        float: left;
        margin: 0 220px 0 0;
        background: url(../image/pn3.png) no-repeat;
        background-size: 22px 22px;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            待接单
        </div>
    </header>
    <div class="aui-card-list ui-selectee" style="margin-top:50px;">
        <!-- <div class="aui-card-list-header ui-selectee" id="pn1">
            设备信息
        </div>
        <div class="aui-card-list-content sortable ui-selectee ui-sortable" contenteditable="true">
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <ul class="aui-list aui-form-list" style="content: none;">
                        <li class="aui-list-item" style="content: none;">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-label">设备编码</div>
                                <div class="aui-list-item-input">
                                    <input type="text" readonly id="equipCode" value="" />
                                </div>
                            </div>
                        </li>
                        <li class="aui-list-item">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-label">设备名称</div>
                                <div class="aui-list-item-input">
                                    <input type="text" readonly id="equipName" value="" />
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div> -->

        <div class="aui-card-list ui-selectee">
            <div class="aui-card-list-header ui-selectee" id="pn2"> 故障信息 </div>
            <div class="aui-card-list-content sortable ui-selectee ui-sortable" contenteditable="true">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <ul class="aui-list aui-form-list" style="content: none;">
                        <li class="aui-list-item">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-label ui-selectee">维修单号</div>
                                <div class="aui-list-item-input ui-selectee">
                                    <input type="text" readonly id="ext03" value="" />
                                </div>
                            </div>
                        </li>
                        <li class="aui-list-item">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-label ui-selectee">故障描述</div>
                                <div class="aui-list-item-input ui-selectee">
                                    <input type="text" readonly id="description" value="" />
                                </div>
                            </div>
                        </li>
                        <li class="aui-list-item">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-label">故障图片</div>
                                <div class="aui-list-item-input">
                                    <div class="aui-content" style="background-color: #ffffff">
                                        <ul class="aui-list-view aui-grid-view" id="imgslist">
                                            <li class="aui-list-view-cell aui-img aui-col-xs-4 aui-padded-5"
                                                id="addpic">
                                                <!-- onclick="imgClick()" -->
                                                <!-- <img class="aui-img-object" style="padding: 5px;"
                                                    src="../image/photo-add.png"> -->
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <div class="aui-content" id="divHtml" style="margin-top: 10px;">

                        </div>
                        <li class="aui-list-item">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-label" style="width: 45%;">故障报修时间</div>
                                <div class="aui-list-item-input">
                                    <input type="text" readonly id="faultdate" value="" />
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <footer class="aui-bar aui-bar-tab ui-selectee" style="color: #f5f5f5;">
        <div class="aui-bar aui-bar-btn aui-bar-btn-full ui-selectee" style="min-height: 2.8rem;font-size: 1.0rem;">
            <div class="aui-bar-btn-item aui-active ui-selectee"
                style="border-color: #f5f5f5;background-color: #03a9f4;" onclick="dispatchWork()">派工</div>
            <div class="aui-bar-btn-item ui-selectee" style="border-color: #f5f5f5;background-color: #03a9f4;"
                onclick="acceptOrder()">接单</div>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script>
    var imageFilter = null;
    var imageBrowser = null;
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
    apiready = function () {
        // 引入过滤压缩模块
        imageFilter = api.require("imageFilter");
        // 引入图片浏览模块
        imageBrowser = api.require('imageBrowser');
        getEmequipmentfaultDataInfo(api.pageParam.sysid); //获取设备故障tab页信息
        getEmequipmentfaultFile(api.pageParam.sysid)
    }
    //获取信息
    function getEmequipmentfaultDataInfo(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEmequipmentfaultList2";
        var data = {
            values: {
                sysid: sysid,
                status: '0',
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    if (list && list.length > 0) {
                        var entity = list[0]
                        $("#ext03").val(entity.ext03);
                        $("#description").val(entity.description);
                        $("#faultdate").val(entity.faultdate);

                        // var imgInfo = data.imgInfo
                        // var imgUrl = imgInfo.url;

                        // var showImgHtml = "<li id='test' class='aui-list-view-cell aui-img aui-col-xs-4  aui-padded-5' style='margin-left: 5px;width:" + normalW + "px;height:" + normalW + "px;' onclick='lookImg(\"" + imgUrl + "\")'><img class='aui-img-object' src='" + imgUrl +
                        //     "' style='width:" + normalW + "px;height:" + normalW + "px;'></li>";
                        // $("#addpic").before(showImgHtml);
                    }
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    //获取信息
    function getEmequipmentfaultFile(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEmequipmentfaultFileList";
        var data = {
            values: {
                sysid: sysid,
                status: '0',
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list)
                    var normalW = $("#addpic img").width();
                    if (list && list.length > 0) {
                        // var str = '';
                        for (var i = 0; i < list.length; i++) {
                            var imgInfo = list[i]
                            var imgUrl = imgInfo.filePath;
                            var showImgHtml = "<li id='test' class='aui-list-view-cell aui-img aui-col-xs-4  aui-padded-5' style='margin-left: 5px;width:" + normalW + "px;height:" + normalW + "px;' onclick='lookImg(\"" + imgUrl + "\")'><img class='aui-img-object' src='" + imgUrl +
                                "' style='width:" + normalW + "px;height:" + normalW + "px;'></li>";
                            $("#addpic").before(showImgHtml);
                        }
                    }
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    // 为图片添加点击预览功能,排除添加按钮
    function lookImg(compressImg) {
        // // 定义一个数组，存储需要预览的图片
        // var browerImgs = [];
        // // 调用图片预览函数
        // browerImgs.push(compressImg);
        // openImageBrowser(browerImgs);
    }
    // 打开图片浏览
    // imgs：需要预览的图片集合
    function openImageBrowser(imgs) {
        imageBrowser.openImages({
            imageUrls: imgs,
            showList: false,
            activeIndex: 0
        });
    }
    //撤单
    function acceptOrder() {
        //修改当前记录 ext01 app状态 为2-驳回
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/acceptOrder";
        var data = {
            values: {
                sysid: api.pageParam.sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    api.hideProgress();
                    // api.toast({
                    //     msg: "保存成功",
                    //     duration: 3000
                    // });
                    alert("接单成功！")

                    api.closeWin();

                    //接单成功后，页面跳转到待维修的二级页面
                    api.openWin({
                        name: 'emequipmentfaultRepaireListDetail',
                        url: 'emequipmentfaultRepaireListDetail' + '.html',
                        pageParam: {
                            sysid: api.pageParam.sysid
                        },
                    })

                    // api.execScript({
                    //     name: api.pageParam.name,
                    //     script: 'doSearch()'
                    // });
                    // api.openWin({
                    //     name: "emequipmentfaltToAcceptOrders",
                    //     url: "emequipmentfaltToAcceptOrders" + '.html',
                    // });

                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });

    }
    function dispatchWork() {
        api.openWin({
            name: "emEquipmentDispatchWork",
            url: "emEquipmentDispatchWork" + '.html',
            pageParam: {
                sysid: api.pageParam.sysid,
                name: 'emequipmentfaltToAcceptOrders'
            },
        });
    }
</script>

</html>